package com.sqx.modules.postPush.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.postPush.entity.PostPush;
import com.sqx.modules.postPush.service.PostPushService;
import com.sqx.modules.postPush.vo.PostPushVo;
import com.sqx.modules.record.service.RecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "招聘信息", tags = {"招聘信息"})
@RequestMapping(value = "/app/postPush")
public class AppPostPushController {

    @Autowired
    private PostPushService postPushService;
    @Autowired
    private RecordService recordService;

    @Login
    @PostMapping("/savePostPush")
    @ApiOperation("添加或修改招聘|求职信息")
    public Result savePostPush(PostPush postPush, @RequestAttribute Long userId) {
        postPush.setUserId(userId);
        return postPushService.savePostPush(postPush);
    }

    @Login
    @GetMapping("/getMyPostPushList")
    @ApiOperation("获取我的的招聘|求职列表")
    public Result getMyPostPushList(Integer page, Integer limit, @RequestAttribute Long userId, PostPushVo postPushVo) {
        postPushVo.setUserId(userId);
        return Result.success().put("data", postPushService.getPostPushList(page, limit, postPushVo, null, null));
    }

    @GetMapping("/getAppPostPushList")
    @ApiOperation("获取所有发布的招聘|求职列表")
    public Result getAppPostPushList(Integer page, Integer limit, Long loginUserId, PostPushVo postPushVo) {
        if (loginUserId!=null && StringUtils.isNotBlank(postPushVo.getKeyWord())){
            recordService.saveRecord(loginUserId, postPushVo.getKeyWord(),postPushVo.getType());
        }
        postPushVo.setStatus(1);
        return Result.success().put("data", postPushService.getAppPostPushList(page, limit, loginUserId, postPushVo));
    }

    @GetMapping("/selectPostPushDetails")
    @ApiOperation("查询招聘|求职信息详情")
    public Result selectPostPushDetails(Long postPushId,Long loginUserId) {
        return Result.success().put("data", postPushService.selectPostPushDetails(postPushId,loginUserId));
    }


    @Login
    @PostMapping("/deletePostPush")
    @ApiOperation("删除招聘或求职")
    public Result deletePostPush(@RequestAttribute("userId") Long userId, Long postPushId) {
        return postPushService.deletePostPush(userId, postPushId);
    }


    @ApiOperation("获取所有有职位的省")
    @GetMapping("getCityList")
    public Result getCityList(String city) {
        return Result.success().put("data", postPushService.getCityList(city));
    }

    @ApiOperation("根据省获取市")
    @GetMapping("getCountyByCity")
    public Result getCountyByCity(String city) {
        return Result.success().put("data", postPushService.getCountyByCity(city));
    }

    @ApiOperation("获取热门城市")
    @GetMapping("getHotCity")
    public Result getHotCity(Integer limitCount) {
        return Result.success().put("data", postPushService.getHotCity(limitCount));
    }

    @ApiOperation("获取市县列表")
    @GetMapping("getCityCounty")
    public Result getCityCounty() {
        return Result.success().put("data", postPushService.getCityCounty());
    }

    @ApiOperation("修改上下架状态")
    @GetMapping("updateStatus")
    public Result updateStatus(Long postPushId) {
        return postPushService.updateStatus(postPushId);
    }

}
